<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>过滤器</title>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/dayjs/1.11.9/dayjs.min.js"></script>
<script src="vue.js"></script>
</head>
<body>
    <div id="root">
        <h1>显示格式化后的时间</h1>
        <h3>{{time | timeFormater | myslice}}</h3>
    </div>
   <script type="text/javascript">
    //全局过滤器
    Vue.filter("myslice",function(val) {
        return val.slice(0,4)
    })
    new Vue({
        el:'#root',
        data: {
            time:1698646879491
        },
        filters: {
            //局部过滤器
            timeFormater(val) {
                return dayjs(val).format('YYYY-MM-DD HH:mm:ss');
            }
        }
    })
   </script>
</body>
</html>